from PyQt6.uic import compileUi

# 输入的.ui 文件路径
input_ui_file = 'resource/dashboard.ui'
# 输出的.py 文件路径
output_py_file = 'app/ui_mainwindow.py'

try:
    with open(input_ui_file, 'r', encoding='utf-8') as ui_file, \
            open(output_py_file, 'w', encoding='utf-8') as py_file:
        # 调用 compileUi 函数进行转换
        compileUi(ui_file, py_file)
    print(f"成功将 {input_ui_file} 转换为 {output_py_file}")
except Exception as e:
    print(f"转换过程中出现错误: {e}")